<template>
  <div class="recommend">
    <scroll class="recommend-content" :data="discList" ref="scroll">
      <div>
        <div class="slider-wrapper" v-if="recommendList.length">
          <slider>
            <div v-for="item in recommendList" :key="item.id">
              <a :href="item.linkUrl">
                <img @load="imgLoad" :src="item.picUrl">
              </a>
            </div>
          </slider>
        </div>
        <div class="recommend-list">
          <h1 class="list-title">热门歌单推荐</h1>
          <ul>
            <li v-for="(item,index) in discList" class="item">
              <div class="icon">
                <img v-lazy="item.imgurl" class="icon-img">
              </div>
              <div class="info">
                <h2 class="name" v-html="item.creator.name"></h2>
                <p class="desc" v-html="item.dissname"></p>
              </div>
            </li>
          </ul>
        </div>
      </div>
      <div v-show="!discList.length" class="loading-content">
        <loading></loading>
      </div>
    </scroll>
  </div>
</template>

<script>
  import Scroll from 'base/scroll/scroll'
  import Slider from 'base/slider/slider'
  import Loading from 'base/loading/loading'
  import {getRecommend, getDiscList} from 'api/recommend'
  import {ERR_OK} from 'api/config'

  export default {
    name: "recommend",
    components: {
      Slider,
      Scroll,
      Loading
    },
    data() {
      return {
        recommendList: [],
        discList: []
      }
    },
    mounted() {
      this._getRecommend()
      this._getDiscList()
    },
    methods: {
      _getRecommend() {
        getRecommend().then((res) => {
          if (res.code === ERR_OK) {
            this.recommendList = res.data.slider
          }
        })
      },
      _getDiscList() {
        getDiscList().then((res) => {
          if (res.code === ERR_OK) {
            this.discList = res.data.list
          }
        })
      },
      imgLoad() {
        if (!this.hasImgload) {
          this.$refs.scroll.refresh()
          this.hasImgload = true
        }
      }
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
  @import "~common/stylus/variable"
  .recommend
    position fixed
    top 88px
    width 100%
    bottom 0
    .recommend-content
      height 100%
      overflow hidden
      .slider-wrapper
        position relative
        width 100%
        overflow hidden
      .recommend-list
        .list-title
          height 65px
          line-height 65px
          text-align center
          color $color-theme
          font-size 14px
        .item
          padding 0 20px 20px 20px
          display flex
          .icon
            flex 0 0 60px
            width 60px
            padding-right 20px
            .icon-img
              display inline-block
              width 100%
          .info
            font-size 14px
            display flex
            flex-direction column
            justify-content center
            line-height 20px
            overflow hidden
            .name
              color $color-text
              margin-bottom 10px
            .desc
              color $color-text-d
      .loading-content
        position absolute
        width 100%
        top 50%
        transform translateY(-50%)

</style>
